#ifndef BUDDY_H_
#define BUDDY_H_

#include <wx/bitmap.h>
#include "Group.h"
#include "Status.h"
#include "interfaces/iProtocolData.h"
#include "database/DBType.h"
#include "database/HistorySession.h"
#include "interfaces/iProtocol.h"

namespace Impp {

enum BuddyPriority{
	BUDDY_PRIORITY_LOW			= 1,
	BUDDY_PRIORITY_NORMAL   	= 2,
	BUDDY_PRIORITY_HIGH			= 3
};

enum BuddyPrivacyList{
	BUDDY_PRIVACY_NOLIST		= 0x00,
	BUDDY_PRIVACY_VISIBLELIST   = 0x02,
	BUDDY_PRIVACY_INVISIBLELIST = 0x04,
	BUDDY_PRIVACY_IGNORED		= 0x08
};

enum BuddyFlag{
	BUDDY_FLAG_NOFLAG 			= 0x000000,
	BUDDY_FLAG_UNREAD_MSG		= 0x000001,
	BUDDY_FLAG_NO_AUTHORIZATION = 0x000002,
	BUDDY_FLAG_VISISBLELIST 	= 0x000004,
	BUDDY_FLAG_INVISIBLELIST 	= 0x000008,
	BUDDY_FLAG_IGNORED 			= 0x000010,
	BUDDY_FLAG_NOT_INLIST 		= 0x000020,
	BUDDY_FLAG_PRIORITY_HIGH    = 0x000040,
	BUDDY_FLAG_PRIORITY_LOW		= 0x000080,
	BUDDY_FLAG_SELF				= 0x000100
};


#define BUDDY_EXT_AVATARHASH					wxT("avatarHash")
#define BUDDY_EXT_NICKNAME						wxT("nickname")
#define BUDDY_EXT_FIRSTNAME						wxT("firstname")
#define BUDDY_EXT_LASTNAME						wxT("lastname")
#define BUDDY_EXT_EMAIL							wxT("email")
#define BUDDY_EXT_GENDER						wxT("gender")

#define BUDDY_EXT_HOME_CITY						wxT("homecity")
#define BUDDY_EXT_HOME_STATE					wxT("homestate")
#define BUDDY_EXT_HOME_PHONE					wxT("homephone")
#define BUDDY_EXT_HOME_FAX						wxT("homefax")
#define BUDDY_EXT_HOME_ADDRESS					wxT("homeaddress")
#define BUDDY_EXT_CELLPHONE						wxT("cellphone")
#define BUDDY_EXT_HOME_ZIP						wxT("homezip")
#define BUDDY_EXT_HOME_COUNTRY_CODE				wxT("homecountrycode")

#define BUDDY_EXT_AGE							wxT("age")
#define BUDDY_EXT_HOMEPAGE						wxT("homepage")
#define BUDDY_EXT_BIRTH_YEAR					wxT("birthyear")
#define BUDDY_EXT_BIRTH_MONTH					wxT("birthmonth")
#define BUDDY_EXT_BIRTH_DAY						wxT("birthday")

#define BUDDY_EXT_SPEAKING_LANGUAGE1			wxT("speakinglng1")
#define BUDDY_EXT_SPEAKING_LANGUAGE2			wxT("speakinglng2")
#define BUDDY_EXT_SPEAKING_LANGUAGE3			wxT("speakinglng3")

#define BUDDY_EXT_ORIGINAL_FROM_CITY			wxT("originalfromcity")
#define BUDDY_EXT_ORIGINAL_FROM_STATE			wxT("originalfromstate")
#define BUDDY_EXT_ORIGINAL_FROM_COUNTRY_CODE	wxT("originalfromcountrycode")

#define BUDDY_EXT_WORK_CITY						wxT("workcity")
#define BUDDY_EXT_WORK_STATE					wxT("workstate")
#define BUDDY_EXT_WORK_PHONE					wxT("workphone")
#define BUDDY_EXT_WORK_FAX						wxT("workfax")
#define BUDDY_EXT_WORK_ADDRESS					wxT("workaddress")
#define BUDDY_EXT_WORK_ZIP						wxT("workzip")
#define BUDDY_EXT_WORK_COUNTRY_CODE				wxT("workcountrycode")
#define BUDDY_EXT_WORK_COMPANY					wxT("workcompany")
#define BUDDY_EXT_WORK_DEPARTMENT				wxT("workdepartment")
#define BUDDY_EXT_WORK_POSITION					wxT("workposition")
#define BUDDY_EXT_WORK_HOMEPAGE					wxT("workhomepage")

#define BUDDY_EXT_NOTES							wxT("notes")

#define BUDDY_EXT_INTEREST1_CATEGORIE			wxT("interest1categorie")
#define BUDDY_EXT_INTEREST1_KEYWORD				wxT("interest1keyword")

#define BUDDY_EXT_INTEREST2_CATEGORIE			wxT("interest2categorie")
#define BUDDY_EXT_INTEREST2_KEYWORD				wxT("interest2keyword")

#define BUDDY_EXT_INTEREST3_CATEGORIE			wxT("interest3categorie")
#define BUDDY_EXT_INTEREST3_KEYWORD				wxT("interest3keyword")

#define BUDDY_EXT_INTEREST4_CATEGORIE			wxT("interest4categorie")
#define BUDDY_EXT_INTEREST4_KEYWORD				wxT("interest4keyword")

#define BUDDY_EXT_LAST_SEEN						wxT("lastseen")

class Group;
class HistorySession;

class Buddy
{
protected:
	friend class Group;
	friend class Impp;
	friend class Database;

protected:
	db_id id;
	db_id accountId;
	wxString screenName;
	wxString customName;
	Status status;
	Group* group;
	iProtocolData* protData;
	wxBitmap avatar;
	wxString statusMsg;
	int/*<BuddyFlag>*/ flags;

	Buddy(db_id id, db_id accountId, const wxString & screenName, const  wxString & customName, Group* group,const int/*<BuddyFlag>*/ & flags);
public:

	virtual ~Buddy();

	db_id getId() const;
	db_id getAccountId() const;
	wxString getName() const;
	wxString getScreenName() const;
	wxString getCustomName() const;

	Group* getGroup() const;

	Status getStatus() const;

	iProtocolData* getProtocolData();

	wxBitmap getAvatar();
	wxString getStatusMsg() const;

	BuddyPriority getPriority() const;
	bool isOnPrivacyList(BuddyPrivacyList list) const;
	bool hasUnredMsg() const;
	bool hasAuthorisation() const;
	bool isInBuddyList() const;
	bool isSelf() const;

	void setExtendedInfo(const wxString & name,const  wxString & value);
	wxString getExtendedInfo(const wxString & name);

	bool getOnlineTime(wxDateTime & time);
	bool getIdleTime(wxDateTime & time);
	bool getIp(wxString & ip);

	void setProtocolData(iProtocolData* data);

private:
	void setGroup(Group* group);
	void setStatus(const Status & status);
	void setScreenName(const wxString & screenName);
	void setCustomName(const wxString & customName);
	void setStatusMsg(const wxString & statusMsg);
	bool setAvatar(wxString file);
	void setPriority(BuddyPriority priority);
	void addToPrivacyList(BuddyPrivacyList list);
	void removeFromPrivacyList(BuddyPrivacyList list);
	void setHasUnredMsg(bool unredMsg);
	void setHasAuthorisation(bool hasAuth);
	void setIsInBuddylist(bool inList);
	int getFlags() const;
};

class SelfBuddy : public Buddy
{
private:
	friend class Group;
	friend class Impp;
	friend class Database;

	wxString rawStatusMsg;

	SelfBuddy(db_id id, db_id accountId, const wxString & screenName, const  wxString & customName, Group* group,const int & flags) :
		Buddy(id, accountId, screenName, customName, group, flags){};

	void setRawStatusMsg(const wxString &rawStatusMsg){
		this->rawStatusMsg=rawStatusMsg;
	};

public:
	wxString getRawStatusMsg(){
		return rawStatusMsg;
	};

};

}

#endif /*BUDDY_H_*/
